# -*- coding: utf-8 *-*
import unittest
from graphs.listgraph import ListGraph
from graphs.matrixgraph import MatrixGraph


class DijkstraTest(unittest.TestCase):

    def test_dijkstra_matrix(self):
        self.run_test1(MatrixGraph())
        self.run_test2(MatrixGraph())
        self.run_test3(MatrixGraph())
        self.run_test4(MatrixGraph())

    def test_dijkstra_list(self):
        self.run_test1(ListGraph())
        self.run_test2(ListGraph())
        self.run_test3(ListGraph())
        self.run_test4(ListGraph())

    def run_test1(self, graph):
        graph.load('inputs/test1.txt')

        items = graph.run_dijkstra('A', 1)
        self.assertEqual(6, items.count())

        items = graph.run_dijkstra('A', 2)
        self.assertEqual(3, items.count())

        items = graph.run_dijkstra('A', 3)
        self.assertEqual(1, items.count())

    def run_test2(self, graph):
        graph.load('inputs/test2.txt')

        items = graph.run_dijkstra('A', 1)
        self.assertEqual(3, items.count())

        items = graph.run_dijkstra('A', 2)
        self.assertEqual(0, items.count())

    def run_test3(self, graph):
        graph.load('inputs/test3.txt')

        items = graph.run_dijkstra('A', 1)
        self.assertEqual(3, items.count())

    def run_test4(self, graph):
        graph.load('inputs/test4.txt')

        items = graph.run_dijkstra('A', 1)
        self.assertEqual(3, items.count())

        items = graph.run_dijkstra('A', 2)
        self.assertEqual(2, items.count())

        items = graph.run_dijkstra('A', 3)
        self.assertEqual(1, items.count())

        items = graph.run_dijkstra('A', 4)
        self.assertEqual(0, items.count())
